<script>
APP = $merge(APP, {
	base: '<?php echo site_url(array('users',$usrAlias,'perbuatan'))?>',
	util: '<?php echo site_url()?>',
	onLoad: ADD_HANDLER.onLoad_add
});

window.addEvent('domready', function(){
	ADD_HANDLER._actionListener_searchPerbuatan_button = $('tpl_kategoriButton');
	ADD_HANDLER._actionListener_searchPerbuatan_pick(
		'<?php echo $deperbData[0]['detachiev_id'] ?>', 
		'<?php echo $deperbData[0]['detachiev_nama']?>', 
		'<?php echo $jenis_options[$deperbData[0]['achiev_jenis']]?>', 
		'<?php echo $deperbData[0]['achiev_bidang']?>', 
		'<?php echo $tingkat_options[$deperbData[0]['detachiev_tingkat']]?>');

	//install kary search button
	$$('.tpl_kary').cloneEvents($('tpl_kary3'),'click');
	$$('.tpl_kary_delete').addEvent('click',function(){
		ADD_HANDLER._destroy_kary_row(this.getParent('tr'));
	});
	ADD_HANDLER.more_kary_counter = <?php echo (count($deperbData) * 2) -1?>
});
</script>
<h2 style="border-bottom: 1px solid #ccc;">Draft Laporan Perbuatan :: Edit</h2>
<form id="frmModal" action="<?php echo site_url(array('users',$usrAlias,'perbuatan','ajax','draft_update')) ?>" method="post">
<input name="perb_id" type="hidden" value="<?php echo $perbData['perb_id']?>" />
<input name="inp[0][0]" type="hidden" value="<?php echo $laporData['lapor_id']?>" />

<h3 style="padding-bottom: 5; margin-bottom: 0">Perbuatan</h3>
<table cellpadding="5" style="margin-left: 5px" cellspacing="0" width="100%">
<tr>
	<td width="20%">Tanggal Lapor:</td>
	<td><input name="inp[3]" value="<?php echo $perbData['perb_tgl_lapor']?>" type="text" class="datepicker validate['required']" style="width: 180px"  /></td>
</tr>
<tr>
	<td>Tanggal Kejadian:</td>
	<td><input name="inp[4]" value="<?php echo $perbData['perb_tgl_kejadian']?>" type="text" class="datepicker validate['required']" style="width: 180px" /></td>
</tr>
<tr>
	<td>Tempat Kejadian:</td>
	<td><input name="inp[5]" value="<?php echo $perbData['perb_tempat_kejadian']?>" type="text" class="validate['required']" style="width: 300px" maxlength="45" /></td>
</tr>
<tr>
	<td valign="top"><div style="padding-top: 2px">Kategori Perbuatan:</div></td>
	<td>
		<input type="hidden" name="inp[6]" />
		<input type="text" value="" disabled="disabled" class="validate['required']" />
		<input id="tpl_kategoriButton" type="button" class="button" value="Search" />
		<table id="prepel" width="100%" style="position:  relative; display: none;">
			<tr>
				<td width="50px">Jenis:</td>
				<td></td>
			</tr>
			<tr>
				<td>Bidang:</td>
				<td></td>
			</tr>
			<tr>
				<td>Tingkat:</td>
				<td></td>
			</tr>
		</table>
	</td>
</tr>
<tr>
	<td>Karyawan Pelaku:</td>
	<td>
		<?php $TMP = (array)$this->karyawan_model->select_by_id($deperbData[0]['kary_id'])->row()?>
		<input id="tpl_kary1" value="<?php echo $TMP['kary_nama']?>" type="text" class="validate['required']" disabled="disabled" />
		<input id="tpl_kary2" name="inp[7][0]" value="<?php echo $deperbData[0]['kary_id']?>" type="hidden" />
		<select style="margin-left:5px" class="validate['required']" name="inp[7][1]">
			<option>--- pilih ---</option>
		<?php foreach ($this->karyawan_history_jabatan_model->getActive($deperbData[0]['kary_id'])
				->result_array() as $row):?>
			<option value="<?php echo $row['kary_jbt_id']?>"
			<?php if ($deperbData[0]['kary_jbt_id']==$row['kary_jbt_id']):?>selected<?php endif;?>>
				<?php echo $row['jbt_nama']." [".$row['dep_nama']."]"?>
			</option>
		<?php endforeach;?>
		</select>
		<input id="tpl_kary3" type="button" class="button" value="Search" />
	</td>
</tr>
<?php
	  $ind=1;
	  foreach($deperbData as $pelaku):
	  if ($pelaku['kary_id'] == $deperbData[0]['kary_id']) continue; //skip the first index 
?>
<tr>
	<td></td>
	<td>
		<?php $TMP = (array)$this->karyawan_model->select_by_id($pelaku['kary_id'])->row()?>
		<input value="<?php echo $TMP['kary_nama']?>" type="text" class="validate['required']" disabled="disabled" />
		<input name="inp[7][<?php echo ++$ind?>]" value="<?php echo $pelaku['kary_id']?>" type="hidden" />
		<select style="margin-left:5px" class="validate['required']" name="inp[7][<?php echo ++$ind?>]">
			<option>--- pilih ---</option>
		<?php foreach ($this->karyawan_history_jabatan_model->getActive($pelaku['kary_id'])
				->result_array() as $row):?>
			<option value="<?php echo $row['kary_jbt_id']?>"
			<?php if ($pelaku['kary_jbt_id']==$row['kary_jbt_id']):?>selected<?php endif;?>>
				<?php echo $row['jbt_nama']." [".$row['dep_nama']."]"?>
			</option>
		<?php endforeach;?>
		</select>
		<input type="button" class="button tpl_kary" value="Search" />
		<a style="margin-left:10px" class="fakeLink tpl_kary_delete">delete</a>
	</td>
</tr>
<?php endforeach?>
<tr>
	<td></td>
	<td><!-- <a class="fakeLink" onclick="ADD_HANDLER.more_kary(this)">tambah</a> --></td>
</tr>
<tr>
	<td valign="top"><div style="padding-top: 2px" >Keterangan:</div></td>
	<td><textarea name="inp[8]" cols="55" rows="4" class="validate['required','length[4,-1]']"><?php echo trim($perbData['perb_keterangan'])?></textarea></td>
</tr>
<tr>
	<td valign="top"><div style="padding-top: 2px">Bukti:</div></td>
	<td>
		<div id="fcUpload"> 
		<ul id="fcUpload-list">
			<?php foreach($buktiperbData as $bukti):?>
			<li class="file " id="file-1" style="background-color: transparent; ">
				<input class="uploadFile validate['group[1,1]']" type="checkbox" name="inp[uploaded][]" 
					value="<?php echo $bukti['perb_dok_id'] ?>" checked="checked">
					<a class="file-title fakeLink" onclick="showImage(
						'<?php echo $bukti['perb_dok_file_name'] ?>',
						'<?php echo $bukti['perb_dok_file_name']?>',
						APP.base+'/ajax/loadImage/<?php echo $bukti['perb_dok_id']?>')">
						<?php echo $bukti['perb_dok_file_name']?>
					</a>
					<span class="file-size"><?php echo number_format($bukti['perb_dok_file_size']/1024,2)." kB"?></span>
			</li>
			<?php endforeach?>
		</ul> 
		<a href="#" id="fcUpload-attach-2">Attach another file</a> 
	</div> 
 	</td>
</tr>
</table>
<div style="border-top:1px solid #ccc; text-align: center; padding-top: 10px; margin-top: 20px">
	<input type="Submit" value="Save" class="button" />
	<input type="button" value="Cancel" class="button" onclick="document.location='<?php echo site_url(array('psdm','perbuatan')) ?>'" />
</div>
</form>
